package com.rupeng.service;

import java.util.List;
import java.util.Map;

import com.rupeng.annotation.RupengCacheable;
import com.rupeng.annotation.RupengUseCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rupeng.mapper.UserMapper;
import com.rupeng.pojo.User;
import com.rupeng.util.CommonUtils;

@Service
@RupengCacheable
public class UserService extends BaseService<User> {
	@Autowired
	private UserMapper userMapper;
	public PageInfo<User> search(Integer pageNum, int pageSize, Map<String, Object> params) {
		PageHelper.startPage(pageNum, pageSize);
		List<User> users = userMapper.search(params);
		return new PageInfo<User>(users);
	}
	@RupengUseCache
	public User login(String loginName, String password) {
		User user = new User();
		if (CommonUtils.isEmail(loginName)) {
			user.setEmail(loginName);
		} else if (CommonUtils.isPhone(loginName)) {
			user.setPhone(loginName);
		} else {
			return null;
		}
		return super.selectOne(user);
	}
}
